define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template','china'],
    function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template,China) {
    // console.log(Config.date_range);
    // console.log(Config.times_30);
    // console.log(Config.users_30);
    var Controller = {
        index: function () {
            // 基于准备好的dom，初始化echarts实例
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '访问曲线'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['访问次数', '访问人数', '访问 IP 数']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.date_range
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '访问次数',
                        type: 'line',
                        stack: 'Total',
                        data: Config.times_30
                    },
                    {
                        name: '访问人数',
                        type: 'line',
                        stack: 'Total',
                        data: Config.users_30
                    },
                    {
                        name: '访问 IP 数',
                        type: 'line',
                        stack: 'Total',
                        data: Config.ips_30
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
            $(window).resize(function () {
                myChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    myChart.resize();
                }, 0);
            });


            var myChart2 = Echarts.init(document.getElementById('echart2'), 'walden');
            var option2 = {
                title : {
                    text: '24小时分布',
                },
                tooltip : {
                    trigger: 'item'
                },
                xAxis: {
                    type: 'category',
                    data: ['0','1', '2', '3', '4', '5', '6', '7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: Config.times_24,
                        type: 'bar',
                        showBackground: true,
                        backgroundStyle: {
                            color: 'rgba(180, 180, 180, 0.2)'
                        }
                    }
                ]
            };
            myChart2.setOption(option2);
            $(window).resize(function () {
                myChart2.resize();
            });
            $(document).on("click", ".btn-refresh2", function () {
                setTimeout(function () {
                    myChart2.resize();
                }, 0);
            });




            var myChart4 = Echarts.init(document.getElementById('echart4'),'emphasis');
            var option4 = {
                title : {
                    text: '访问地区分布',
                    subtext: '',
                },
                tooltip : {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    x:'left',
                    data:['安装量']
                },
                dataRange: {
                    x: 'left',
                    y: 'bottom',
                    splitList: [
                        {start: 500},
                        {start: 300, end: 500},
                        {start: 100, end: 300},
                        {start: 50, end: 100},
                        {start: 10, end: 50},
                        {start: 0, end: 10 },
                        {end: 0}
                    ],
                    color: ['#E0022B', '#E09107', '#A3E00B']
                },
                toolbox: {
                    show: true,
                    orient : 'vertical',
                    x: 'right',
                    y: 'center',
                    feature : {
                        mark : {show: true},
                        dataView : {show: true, readOnly: false},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                roamController: {
                    show: true,
                    x: 'right',
                    mapTypeControl: {
                        'china': true
                    }
                },
                geo: {
                    // 这个是重点配置区
                    map: "china", // 表示中国地图

                },
                series : [
                    {
                        name: '下载量',
                        type: 'map',
                        mapType: 'china',
                        roam: false,
                        itemStyle:{
                            normal:{
                                label:{
                                    show:true,
                                    textStyle: {
                                        color: "rgb(249, 249, 249)"
                                    }
                                }
                            },
                            emphasis:{label:{show:true}}
                        },
                        data:Config.area_34
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart4.setOption(option4);



        }
    };

    return Controller;
});
